package de.jonasjelten.jcalc.mathExps;

/**
 *
 * @author Michael Enßlin, Jonas Jelten
 */
import de.jonasjelten.jcalc.api.JCalc;
import de.jonasjelten.jcalc.exception.JMathematicalException;
import de.jonasjelten.jcalc.math.JNumber;
import java.math.BigDecimal;
import java.math.BigInteger;

public class JConst extends JZeroArgMathExp {

    final JNumber value;

    public JConst(BigInteger value, int scale, boolean isComplex, JCalc jcalc) throws JMathematicalException {
        super(jcalc);
        if (isComplex) {
            this.value = new JNumber(BigDecimal.ZERO, new BigDecimal(value, -scale));
        } else {
            this.value = new JNumber(new BigDecimal(value, -scale), BigDecimal.ZERO);
        }
    }

    public JConst(JNumber value, JCalc jcalc) {
        super(jcalc);
        this.value = value;
    }

    public JConst(double value, JCalc jcalc) throws JMathematicalException {
        this(new JNumber(BigDecimal.valueOf(value)), jcalc);
    }

    public JConst(String value, JCalc jcalc) throws JMathematicalException {
        this(new JNumber(value), jcalc);
    }

    @Override
    public JNumber eval() {
        return value;
    }

    @Override
    public String toString() {
        if (value != null) {
            return value.toString();
        } else {
            return "[NOT INITED]";
        }
    }

    @Override
    public boolean isTrivial() {
        return true;
    }
}
